# coding=utf-8
"""
项目入口
初始化项目配置
"""

from flask import Flask
from flask_script import Manager
from flask_sqlalchemy import SQLAlchemy
from common.libs.UrlManager import UrlManager
from common.libs.TemplateAdvance import *
import os

class Application(Flask) :
    def __init__(self, import_name, template_folder = None, root_path = None ):
        super( Application, self ).__init__( import_name, template_folder=template_folder, root_path=root_path, static_folder = None)
        self.config.from_pyfile("config/base_settings.py")
        if "ops_config" in os.environ:
            self.config.from_pyfile( "config/%s_settings.py" % (os.environ["ops_config"]) )
        db.init_app( self )

#初始化数据库
db = SQLAlchemy( )
#初始化整个项目
app = Application( __name__, template_folder = os.getcwd() + "/web/templates/", root_path = os.getcwd() )
#app进行包装
manager = Manager( app )


#jinja模板引擎函数扩展
app.add_template_global(UrlManager.buildUrl, "buildUrl")
app.add_template_global(UrlManager.buildStaticUrl, "buildStaticUrl")
app.add_template_global(UrlManager.buildImageUrl, "buildImageUrl")
app.add_template_global(contains, 'contains')
